﻿// Programmer: JR Padfield
// Description: 
// Version: 1
// Date: 

﻿namespace TheWorldLibrary.Worlds
{
    public struct Tile
    {
        public int TileIndex;
        public int TileSetIndex;

        public Tile(int tileIndex, int tileSetIndex)
        {
            TileIndex = tileIndex;
            TileSetIndex = tileSetIndex;
        }
    }

    public struct Attributes
    {
        public int attribute;

        public Attributes(int attType)
        {
            attribute = attType;
        }
    }

    public class MapLayerData
    {
        #region Fields

        public string MapLayerName;
        public int Width;
        public int Height;
        public Tile[] Layer;
        public Attributes[] attribute;

        #endregion

        #region Constructors

        private MapLayerData()
        {
        }

        public MapLayerData(string mapLayerName, int width, int height)
        {
            MapLayerName = mapLayerName;
            Width = width;
            Height = height;

            Layer = new Tile[height * width];
            attribute = new Attributes[height * width];
        }

        public MapLayerData(string mapLayerName, int width, int height, int tileIndex, int tileSet)
        {
            MapLayerName = mapLayerName;
            Width = width;
            Height = height;

            Layer = new Tile[height * width];

            Tile tile = new Tile(tileIndex, tileSet);

            for (int y = 0; y < height; y++)
                for (int x = 0; x < width; x++)
                    SetTile(x, y, tile);

            attribute = new Attributes[height * width];;
            for (int x = 0; x < width; x++)
                for (int y = 0; y < height; y++)
                    SetAttributeTile(x, y, 0);
        }

        #endregion

        #region Methods

        public void SetTile(int x, int y, Tile tile)
        {
            Layer[y * Width + x] = tile;
        }

        public void SetTile(int x, int y, int tileIndex, int tileSet)
        {
            Layer[y * Width + x] = new Tile(tileIndex, tileSet);
        }

        public Tile GetTile(int x, int y)
        {
            return Layer[y * Width + x];
        }

        public void SetAttributeTile(int x, int y, int att)
        {
            attribute[y * Width + x] = new Attributes(att);
        }

        public Attributes GetAttribute(int x, int y)
        {
            return attribute[y * Width + x];
        }

        #endregion
    }
}

